//多个数据最终变成了一个数据
let arr1 = [{price:30,count:2},{price:30,count:3},{price:30,count:4}].reduce(function(prev, next){
	return prev + next.price*next.count;
},0);
console.log(arr1);

let arr2 = [[1,2,3],[4,5,6],[7,8,9]].reduce(function(prev, next){
	return prev.concat(next);
});
console.log(arr2);

let keys = ['name','age']
let values = ['zf',12]
let obj = keys.reduce((prev,next,index)=>{
	console.log(prev,next)
	prev[next] = values[index]
	return prev
},{})
console.log(obj)
// (1,2,3) -> 3 逗号运算符


//redux的compose  组合多个函数
function sum(a,b){
	return a+b
}
function toUpper(str){
	return str.toUpperCase();
}
function add(str){
	return "***"+str+"***"
}
function compose(...fns){
	return function(...args){
		let lastFn = fns.pop();//shift
		return fns.reduceRight((a,b)=>{//reduce
			return b(a)
		},lastFn(...args))
	}
}
let r = compose(add,toUpper,sum)('zfpx','jg')
// let r = compose(sum,toUpper,add)('zfpx','jg')
console.log(r)
function compose1(...fns){
	return fns.reduce((a,b)=>{//此时返回的函数，是通过reduce方法返回的
		return (...args)=>{
			return a(b(...args))
		}
	})
}
let r1 = compose1(add,toUpper,sum)('abcd','ef')
console.log(r1)

//自己实现一个reduce
Array.prototype.reducee = function(callback,prev){
	for(let i=0;i<this.length;i++){
		if(prev == undefined){
			prev = callback(this[i],this[i+1],i+1,this)
			i++
		}else{
			prev = callback(prev,this[i],i,this)
		}
	}
	return prev;
};
let r2 = [1,2,3].reducee((a,b,index,cur)=>{
	return a+b
},100)
console.log(r2)

let newArr = [1,2,3].map(item=>item*2); //循环每一项 都*2
[1,2,3].filter(item=>item!=2); 			//删除为2的 返回true表示留下
[1,2,3,4].some((item)=>item==5);		//找true
[1,2,3,4,5].every((item)=>item==1); 	//看看有没有不等于1的 有的话返回false
[1,2,3].find(item=>item==2) 			//找到后返回找到的那一项 找不到返回undefind
[1,2,3].indexOf(1)>-1   
[1,2,3].includes(2)  					//true




let arr = [1,2,3,4,5,66];
//		arr.b = '100';
//	for(let key in arr){
//		console.log(key);
//	}
let result = arr.some(function(item, index){
	//return item.toString().indexOf(6)>-1;
	return /6\d/.exec(item);
});
console.log(result);

function a(b){
	return function (c){
		return b+c;
	}
}
console.log(a(1)(2));

let aa = b => c => b+c;
console.log(aa(1)(2));

[1,2,3].forEach(item => {  console.log(item)});